﻿using CRM.Infrastructure.Dto.Request.Right;
using CRM.Infrastructure.Dto.Response.Right;
using CRM.Service.Instance;
using CRM.Service.Interface;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace CRM.Api.Admin.Controllers
{
    /// <summary>
    /// 权限
    /// </summary>
    public class RightController : BaseController
    {
        private readonly I_Right_Service _right_Service;
        public RightController(I_Right_Service right_Service, I_Login_Service login_Service) : base(login_Service)
        {
            _right_Service = right_Service;
        }
        /// <summary>
        /// 获取所有权限
        /// </summary>
        /// <param name="isPublish"></param>
        /// <param name="isBan"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Rights(int? isPublish = -1, int? isBan = -1)
        {

            var result = await _right_Service.Get_Rights(new Right_Request_Dto
            {
                isBan = isBan ?? -1,
                isPublish = isPublish ?? -1
            });
            return Ok(result);

        }
        /// <summary>
        /// 获取配置下的权限
        /// </summary>
        /// <param name="id"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_RightConfig_Details(string id, int? page = 1, int? limit = 10)
        {
            var result = await _right_Service.Get_RightConfig_Details(id);
            return Ok(result);
        }
        /// <summary>
        /// 获取所有配置
        /// </summary>
        /// <param name="isPublish"></param>
        /// <param name="isBan"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_RightConfig(int? isPublish = -1, int? isBan = -1)
        {

            var result = await _right_Service.Get_RightConfig(new Right_Request_Dto
            {
                isBan = isBan ?? -1,
                isPublish = isPublish ?? -1
            });
            return Ok(result);

        }
        /// <summary>
        /// 修改配置[config是配置下的权限，check是配置下的初始化职位]
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <param name="configs"></param>
        /// <param name="check"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Change_Config(string id, string name, string configs, string check)
        {

            var result = await _right_Service.Change_Config(new RightConfig_Response_Dto
            {
                id = id,
                name = name,
                configs = configs.Split(',', '[', ']', '"', '\\'),
                check = check.Split(',', '[', ']', '"', '\\'),
            });
            return Ok(result);

        }

    }
}
